package com.java.wmovie.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.java.wmovie.entity.User;
import com.java.wmovie.mapper.UserMapper;
import com.java.wmovie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class registerController {
    @Autowired
    UserService userService;
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/register")
    public String register(){
        return "/register";
    }

    @RequestMapping("/registers")
    public String registers(User user,Model model , HttpSession session, @RequestParam("u_name")String uName,@RequestParam("u_password")String uPassword,
                            @RequestParam("gender")String gender,@RequestParam("number")String number){
        User user1=userMapper.selectOne(new QueryWrapper<User>().eq("u_name",uName).eq("u_password",uPassword).eq("number",number).eq("gender",gender));
        if(ObjectUtils.isEmpty(user1)){
            if (uName == null){
                model.addAttribute("msg2","不能有空值");
                return "/register";
            }else {
                userService.save(user);
                return "redirect:/";
            }
        }else {
            model.addAttribute("msg2","项目已存在");
            return "redirect:/register";
        }
    }
}
